<!--交易流水-->
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="交易流水号" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入交易流水号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
        <el-form-item label="交易账户" prop="tradeAccount">
        <el-input
          v-model="queryParams.tradeAccount"
          placeholder="请输入交易账户：更改为相关商户名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="交易账户类型" prop="tradeAccountType">
        <el-select v-model="queryParams.tradeAccountType" clearable placeholder="请选择">
<!--          1:微信，2:支付宝，3:银行卡，4:拉卡拉（-->
          <el-option
            v-for="item in tradeAccountTypes"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="交易账号" prop="tradeAccountNo">
        <el-input
          v-model="queryParams.tradeAccountNo"
          placeholder="请输入交易账号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付方式," prop="payWay">
<!--         1:微信扫码，2:支付宝扫码，3:微信公众号，4:认证支付，5:实时代付到银行卡，20:批量代付到银行卡-->
        <el-select v-model="queryParams.payWay" clearable placeholder="请选择">
          <el-option
            v-for="item in payWays"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="订单金额" prop="amount">
        <el-input
          v-model="queryParams.amount"
          placeholder="请输入订单金额：支付订单金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付金额" prop="payAmount">
        <el-input
          v-model="queryParams.payAmount"
          placeholder="请输入支付金额：用来记录用户实际支付金额，目前=订单金额就行。"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="结算金额" prop="finalAmount">
        <el-input
          v-model="queryParams.finalAmount"
          placeholder="请输入结算金额：平台这边定义字段，暂时不设值，拉卡拉对账文件里面也会有，存到导入的表里面，对账的时候显示拉卡拉那边的结算金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="交易对手" prop="tradeUser">
        <el-input
          v-model="queryParams.tradeUser"
          placeholder="请输入交易对手：入金(提现以外)的时候：海链物联，出金"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="对手账号" prop="dsAccount">
        <el-input
          v-model="queryParams.dsAccount"
          placeholder="请输入对手账号：入金的时候：海链的拉卡拉账号，出的时候是商户对应银行卡号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="交易渠道" prop="tradeQudao">
        <el-select v-model="queryParams.tradeQudao" clearable placeholder="请选择">
          <el-option
            v-for="item in tradeQudaos"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="渠道订单号" prop="qudaoOrderNo">
        <el-input
          v-model="queryParams.qudaoOrderNo"
          placeholder="请输入渠道订单号：拉卡拉生成的订单号，具体什么时候回传需要调查。"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="交易结果" prop="tradeResult">
<!--        1:处理中，2:成功，3:失败。-->
        <el-select v-model="queryParams.tradeResult" clearable placeholder="请选择">
          <el-option
            v-for="item in tradeResults"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="发起交易日期" prop="tradeDateFq">
        <el-date-picker clearable
          v-model="queryParams.startTradeDateFq"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择发起交易日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="---" prop="tradeDateFq">
        <el-date-picker clearable
          v-model="queryParams.endTradeDateFq"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择发起交易日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="支付截止日期" prop="tradeDateJz">
<!--        ：订单有效时间计算，二维码三分钟，H5因为是系统通知微信，所以自己传的时间，没穿就是空。其它都是1小时。根据发起交易日期来计算。-->
        <el-date-picker clearable
          v-model="queryParams.startTradeDateJz"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择支付截止日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="---" prop="tradeDateJz">
        <!--        ：订单有效时间计算，二维码三分钟，H5因为是系统通知微信，所以自己传的时间，没穿就是空。其它都是1小时。根据发起交易日期来计算。-->
        <el-date-picker clearable
          v-model="queryParams.endTradeDateJz"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择支付截止日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['order:order:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="交易流水号" align="center" width="165"  prop="orderNo" />
      <el-table-column label="业务订单号" align="center" width="165"  prop="businessOrderPlanNo" />
      <el-table-column label="交易账户类型" align="center" prop="tradeAccountType" >
        <template slot-scope="scope">
          <span v-if="scope.row.tradeAccountType==1">微信</span>
          <span v-if="scope.row.tradeAccountType==2">支付宝</span>
          <span v-if="scope.row.tradeAccountType==3">银行卡</span>
          <span v-if="scope.row.tradeAccountType==4">拉卡拉</span>
        </template>
      </el-table-column>
<!--      ：暂定1:微信，2:支付宝，3:银行卡，4:拉卡拉-->
      <el-table-column label="交易账号" align="center" width="165"  prop="tradeAccountNo" />
      <el-table-column label="交易账户" align="center" prop="tradeAccount" />
      <el-table-column label="用户类型" align="center" prop="userType" >
        <template slot-scope="scope">
        <!--：租客个人用户（前端客户），2：企业商户-->
          <span v-if="scope.row.userType==1">租客个人用户</span>
          <span v-if="scope.row.userType==2">企业商户</span>
        </template>
      </el-table-column>
      <el-table-column label="支付方式" align="center" prop="payWay" >
      <!--      , 1:微信扫码，2:支付宝扫码，3:微信公众号，4:认证支付，5:实时代付到银行卡，20:批量代付到银行卡"-->
      <template slot-scope="scope">
        <span v-if="scope.row.payWay==1">微信扫码</span>
        <span v-if="scope.row.payWay==2">支付宝扫码</span>
        <span v-if="scope.row.payWay==3">微信公众号</span>
        <span v-if="scope.row.payWay==4">认证支付</span>
        <span v-if="scope.row.payWay==5">实时代付到银行卡</span>
      </template>
      </el-table-column>
      <el-table-column label="结算金额" align="center" prop="finalAmount" />
      <el-table-column label="交易对手" align="center" prop="tradeUser" />
      <el-table-column label="对手账号" align="center" prop="dsAccount" />
      <el-table-column label="交易渠道" align="center" prop="tradeQudao" />
      <el-table-column label="渠道订单号" align="center"  width="165"  prop="qudaoOrderNo" />
      <el-table-column label="交易结果" align="center" prop="tradeResult" >
        <!-- 1:处理中，2:成功，3:失败。-->
        <template slot-scope="scope">
          <span v-if="scope.row.tradeResult==1">处理中</span>
          <span v-if="scope.row.tradeResult==2">成功</span>
          <span v-if="scope.row.tradeResult==3">失败</span>
        </template>
      </el-table-column>
      <el-table-column label="返回码" align="center" prop="returnCode" />
      <el-table-column label="返回信息" align="center" prop="returnMsg" />
      <el-table-column label="发起交易日期" align="center" prop="tradeDateFq" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.tradeDateFq, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="执行交易日期" align="center" prop="tradeDateZx" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.tradeDateZx, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="支付截止日期" align="center" prop="tradeDateJz" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.tradeDateJz, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="费率" align="center" prop="tradeRate" />
      <el-table-column label="手续费" align="center" prop="commissionFee" />
      <el-table-column label="订单金额" align="center" prop="amount" />
      <el-table-column label="支付金额" align="center" prop="payAmount" />
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listOrder } from "@/api/property/order";
import {listTable} from "@/api/tool/gen";

export default {
  name: "Order",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 支付订单（支付流水信息）表格数据
      orderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //支付方式
      payWays:[
        {value: 1, label: '微信扫码'},
        {value: 2, label: '支付宝扫码'},
        {value: 3, label: '微信公众号'},
        {value: 4, label: '认证支付'},
        {value: 5, label: '代付到银行卡'},
      ],tradeQudaos:[
        {value: 1, label: '拉卡拉'},
      ],
      tradeResults:[
        {value: 1, label: '处理中'}
        ,{value: 2, label: '成功'}
        ,{value: 3, label: '失败'},
      ],
      //<!--  交易账户类型        1:微信，2:支付宝，3:银行卡，4:拉卡拉（-->
      tradeAccountTypes:[
        {value: 1, label: '微信'},
        {value: 2, label: '支付宝'},
        {value: 3, label: '银行卡'},
        {value: 4, label: '拉卡拉'},
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderNo: null,
        tradeAccount: null,
        tradeAccountType: null,
        tradeAccountNo: null,
        userId: null,
        userType: null,
        operationType: null,
        payWay: null,
        amount: null,
        payAmount: null,
        finalAmount: null,
        discountAmount: null,
        tradeUser: null,
        dsAccount: null,
        tradeQudao: null,
        qudaoOrderNo: null,
        tradeResult: null,
        returnCode: null,
        returnMsg: null,
        tradeDateFq: null,
        tradeDateZx: null,
        tradeDateZf: null,
        tradeDateJz: null,
        tradeRate: null,
        commissionFee: null,
        beginTime: null,
        endTime: null,
        checkState: null,
        checkTime: null,
        checkUserid: null,
        checkFailReason: null,
        outOrderNo: null,
        dzState: null,
        certificateJz: null,
        productSubject: null,
        productBody: null,
        canClearingAmount: null,
        remarks: null,
        delFlg: null,
        createUserid: null,
        updateUserid: null,
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询支付订单（支付流水信息）列表 */
    getList() {
      console.log(this.queryParams)
      this.loading = true;
      listOrder(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderNo: null,
        tradeAccount: null,
        tradeAccountType: null,
        tradeAccountNo: null,
        userId: null,
        userType: null,
        operationType: null,
        payWay: null,
        amount: null,
        payAmount: null,
        finalAmount: null,
        discountAmount: null,
        tradeUser: null,
        dsAccount: null,
        tradeQudao: null,
        qudaoOrderNo: null,
        tradeResult: null,
        returnCode: null,
        returnMsg: null,
        tradeDateFq: null,
        tradeDateZx: null,
        tradeDateZf: null,
        tradeDateJz: null,
        tradeRate: null,
        commissionFee: null,
        beginTime: null,
        endTime: null,
        checkState: null,
        checkTime: null,
        checkUserid: null,
        checkFailReason: null,
        outOrderNo: null,
        dzState: null,
        certificateJz: null,
        productSubject: null,
        productBody: null,
        canClearingAmount: null,
        remarks: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        createTime: null,
        updateUserid: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('order/order/export', {
        ...this.queryParams
      }, `order_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
